package com.neuedu.corejava.ch5;

public class Recursion {
	
	//20190731
	public static int sum(int num,int sum){
		sum+=num--;
		if(num==0){//递归调用时，必须有递归终止条件，否则会产生死循环
			return sum;
		}else {
			return sum(num,sum);
		}
	}
	
	//自己尝试
	private static int sum1(int num,int sum){
		
		sum+=num++;
		if(num==100){
			return sum;
		}else {
			return sum(num,sum);
		}
	}
	

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//使用递归算法：计算1~100的求和
		//10分钟
		int a=100;
		int result=new Recursion().sum( a, 0);
		System.out.println(result);
		
		//使用递归算法技术阶乘：n！~课后练习

	}

}
